
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <boost/convert.hpp>
#include <boost/locale.hpp>

using namespace std;
using namespace boost::locale;

string to_local(const string str)
{
#ifdef _WIN32
    return conv::between(str, "GBK", "UTF-8");
#else
    return str;
#endif
}

string form_local(const string str)
{
#ifdef _WIN32
    return conv::between(str, "UTF-8", "GBK");
#else
    return str;
#endif
}

int main(int argc, char const *argv[])
{
    string str{"你好世界"}; // 在windows中打印乱码
    auto gbk = conv::between(str, "GBK", "UTF-8");
    cout << str << endl;
    cout << gbk << endl;

    cout << to_local("请输入：") << flush;
    string ingbk;
    cin >> ingbk;

    if (ingbk == str)
    {
        cout << "ingbk == utf-8" << endl;
    }

    if (ingbk == gbk)
    {
        cout << "ingbk == gbk" << endl;
    }

    auto conv = conv::between(ingbk, "UTF-8", "GBK");

    cout << to_local("转换后") << endl;

    if (conv == str)
    {
        cout << "conv == utf-8" << endl;
    }

    if (conv == gbk)
    {
        cout << "conv == gbk" << endl;
    }

    return 0;
}
